﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XCommunity.Views;
using XCommunity.Frames;

namespace XCommunity.Forums.Views
{
  public class TopicItemView : ViewObject
  {

    public TopicItemView( ViewService service, ITopicFrame topic )
      : base( service )
    {
      if ( topic == null )
        throw new ArgumentNullException( "topic" );

      _topic = topic;
    }

    private ITopicFrame _topic;

    protected ITopicFrame Topic
    {
      get { return _topic; }
    }



    public string Launcher
    {
      get { return Topic.Meta.Launcher; }
    }


    public string Title
    {
      get { return Topic.Meta.Title; }
    }

    public int Responses
    {
      get { return Topic.Responses.Count(); }
    }

    public int TopicId
    {
      get { return Topic.TopicId; }
    }

    public DateTime LastPostPublishDate
    {
      get { return Topic.GetLastPublishPost().PublishDate.ToLocalTime(); }
    }

    public string LastPublishPostAuthor
    {
      get { return Topic.GetLastPublishPost().Author; }
    }

    public DateTime LastPostModifyDate
    {
      get { return Topic.GetLastModifyPost().LastModifyDate.ToLocalTime(); }
    }

    public string LastModifyPostAuthor
    {
      get { return Topic.GetLastModifyPost().Author; }
    }


    public override object BaseObject
    {
      get { return Topic; }
    }
  }
}
